package cn.itcast.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import reactor.core.publisher.Mono;

@Slf4j
@Configuration
public class FilterConfiguration {
    @Bean
    @Order(-1)
    public GlobalFilter globalFilter() {
        return (((exchange, chain) -> {
            log.info("过滤器前置阶段");

            return chain.filter(exchange).
                    then(Mono.fromRunnable(() ->
                            log.info("过滤器的post阶段")));
        }));
    }
}
